
def prostoe(n):
    for i in range(2,n):
        if n % i == 0:
            return False
    return True

def max_prostoe(num):
    num_str = str(num)
    if len(num_str) != 4 :
        return 0
    m = 0
    for i in range(len(num_str)):
        for j in range(i+1,len(num_str)+1):
            k = int(num_str[i:j])
            if prostoe(k) and k>m:
                m=k
    return m

num = int(input(''))
m = max_prostoe(num)
print(m)